// ++++++++++++++++++++++++++++++++++++++++
// 《零基础Go语言算法实战》源码
// ++++++++++++++++++++++++++++++++++++++++
// Author:廖显东（ShirDon）
// Blog:https://www.shirdon.com/
// Gitee:https://gitee.com/shirdonl/goAlgorithms.git
// Buy link :https://item.jd.com/14101229.html
// ++++++++++++++++++++++++++++++++++++++++

package main

import "fmt"

// 此函数使用冒泡排序算法对整数切片进行排序
func bubbleSort(array []int) {
	// 获取整数切片的长度
	length := len(array)
	// 遍历整数切片中的每个元素
	for i := 0; i < length-1; i++ {
		// 遍历切片的未排序部分
		for j := 0; j < length-i-1; j++ {
			// 如果顺序错误，则交换相邻元素
			if array[j] > array[j+1] {
				array[j], array[j+1] = array[j+1], array[j]
			}
		}
	}
}

func main() {
	array := []int{33, 23, 56, 7, 8, 18, 99, 28}
	bubbleSort(array)
	fmt.Println(array)
}

//$ go run bubbleSort.go
//[7 8 18 23 28 33 56 99]
